package sonok.global;

import java.awt.Point;

public class guiSimpleTable {
	
	public class gstCell{
		guiSimpleTable owner;
		
		public gstCell(guiSimpleTable Owner) {
			owner = Owner;
		}
		
		//TODO vvv
		public int getRow() {
			return owner.getRowFor(this);
		}		
		public int getCol() {
			return owner.getColumnFor(this);
		}
		
		public void setWidth(int w) {
			owner.setColumnSize(getCol(),w);
		}		
		public void setHeight(int h) {
			owner.setRowSize(getCol(),h);
		}
	}
	
	private gstCell[][] cells;
	private int[] ColumnSizes;
	private int[] RowSizes;
	private int ColumnCount, RowCount;
	
	public guiSimpleTable(final int Column_Count, final int Row_Count) {
		buildTable(Column_Count, Row_Count);
	}
	
	private void buildTable(final int Column_Count, final int Row_Count) {
		cells = new gstCell[Column_Count][Row_Count];
		//TODO Fill old cells?
		
		ColumnCount = Column_Count;
		ColumnSizes = new int[Column_Count];
		
		RowCount = Row_Count;
		RowSizes = new int[Row_Count];
	}

  //Getter & Setter	
	public void setColumnCount(int columnCount) {
		ColumnCount = columnCount;
	}
	public int getColumnCount() {
		return ColumnCount;
	}	
	public void setRowCount(int rowCount) {
		RowCount = rowCount;
	}
	public int getRowCount() {
		return RowCount;
	}
	
	public void setColumnSize(int column, int size) {
		if ((column >= 0)&&(column<ColumnCount)) {
			ColumnSizes[column] = size;
		} else {
			//TODO Throw Exception
		}
	}
	public void setRowSize(int row, int size) {
		if ((row >= 0)&&(row<RowCount)) {
			RowSizes[row] = size;
		} else {
			//TODO Throw Exception
		}
	}
	public void setColumnSizes(int[] columnSizes) {
		if (columnSizes.length == ColumnSizes.length) {
			ColumnSizes = columnSizes;
		} else {
			//TODO Throw Exception
		}
	}
	public void setRowSizes(int[] rowSizes) {
		if (rowSizes.length == RowSizes.length) {
			RowSizes = rowSizes;
		} else {
			//TODO Throw Exception
		}
	}
	public void setAllColumnSizes(int columnSize) {
		for (int i = 0; i < ColumnCount; i++) {
			ColumnSizes[i] = columnSize;
		}
	}
	public void setAllRowSizes(int rowSize) {
		for (int i = 0; i < RowCount; i++) {
			RowSizes[i] = rowSize;
		}
	}

	public Point getCoordFor(gstCell c){
		for (int i = 0; i < cells.length; i++)
		for (int j = 0; j < cells.length; j++) {
			if (cells[i][j] == c) {
				return new Point(i, j);
			}
		}
		
		return null;
	}	
	public int getColumnFor(gstCell c) {
		return getCoordFor(c).x;
	}
	public int getRowFor(gstCell c) {
		return getCoordFor(c).y;
	}
	
}
